<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Auth;   //引入Auth类
use App\Author; //引入Author类
use App\User;
use App\Novel;  //引入Novel类
use Gregwar\Captcha\CaptchaBuilder;


class AuthorController extends Controller
{
  public function getWorks(){
    $user = Auth::user();
    // dd($user->uid);
    $novels = Novel::where('uid', $user->uid)->orderby('pubtime','desc')->get();    //取出小说信息
    // dd($novels);
    return view('admin/works', ['novels'=>$novels]);             //把数据传到works页面
  }

  public function getSubscribe(){
  	return view('admin/subscribe');
  }

  public function getReward(){
  	return view('admin/reward');
  }

  public function getComments(){
  	return view('admin/comments');
  }

  public function getAuthorset(){
    $uid = Auth::user()->uid;
    $user = User::find($uid);
  	return view('admin/authorset',['user' => $user]);
  }
  public function postAuthorset(Request $req){
    $uid = Auth::user()->uid;
    $user = User::find($uid);
    $data = $req->all();
    $user->desc = $data['desc'];
    $user->works = $data['works'];
    //上传头像
    $path = "upload/";                                       //指定路径
    // dd($req['cover_img']);
    $file = $req['pic'];                               //取到图片文件
    $file_name = $uid . time() . $file->getClientOriginalName(); //文件名
    $file->move($path, $file_name);                          //上传
    $user->user_img ='/' . $path . $file_name;
    $user->save();
    return redirect('authorset');
  }

  public function captcha(){
    $builder = new CaptchaBuilder;
    $builder->build();
    header('Content-type: image/jpeg');
    $builder->output();
  }




}
